<template>
  <div class="app-container">
    <content-title></content-title>
    <el-form ref="formData" :model="formData" :rules="rules" class="form-container"
             label-width="100px" label-position="right">
           <el-form-item label="部门名称" prop="name">
       <el-input v-model="formData.name"></el-input>
     </el-form-item>
     <el-form-item label="描述" prop="description">
       <el-input v-model="formData.description"></el-input>
     </el-form-item>

        <el-form-item>
            <go-back :opt-type="optType"></go-back>
            <el-button type="primary" @click="onSubmit" v-show="optType!=3">保存</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>

<script>

  import {detail, save, update} from "@/api/department";

  export default {
    name: 'departmentDetail',
    props: {
      optType: {
        type: Number,
        default: 3
      }
    },
    data() {
      return {
        formData: {
            id:'',
            name:'',
            description:'',
        },
        rules: {
          name:[
            {required: true, message: '请输入部门名称', trigger: 'blur'},
          ],
        },
        tempRoute: {}
      }
    },
    computed: {},
    created() {
      this.initOthers()
      this.getDetail()
      this.tempRoute = Object.assign({}, this.$route)
    },
    methods: {
      initOthers() {

      },
      getDetail() {
        this.$business.getDetailById(this,detail,(data)=>{
          this.formData = data
        })
      },
      onSubmit() {
        this.$business.save(this, save, update,"departmentList");
      }
    }
  }
</script>

